/*
 * LaporanLabaRugi.java
 *
 * Created on August 19, 2010, 9:01 AM
 */
package com.ivanbiz.gui;

import com.ivanbiz.dao.LabaRugiDAO;
import com.ivanbiz.helper.CenterRenderer;
import com.ivanbiz.helper.RightRenderer;
import com.ivanbiz.impl.LabaRugiDAOImpl;
import com.ivanbiz.model.BiayaLain;
import com.ivanbiz.model.ItemNota;
import com.ivanbiz.model.ItemNotaLain;
import com.ivanbiz.model.ItemPembelian;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author  User
 */
public class LaporanLabaRugi extends javax.swing.JInternalFrame {

    List<ItemNota> listItemNota = new ArrayList<ItemNota>();
    List<ItemNotaLain> listItemNotaLain = new ArrayList<ItemNotaLain>();
    List<ItemPembelian> listItemPembelian = new ArrayList<ItemPembelian>();
    List<BiayaLain> listBiayaLain = new ArrayList<BiayaLain>();
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
    LabaRugiDAO labaRugiDAO = new LabaRugiDAOImpl();

    /** Creates new form LaporanLabaRugi */
    public LaporanLabaRugi() {
        initComponents();
        updateData();
    }

    private void updateTableBiayaLain() {
        String[] judul = {"Nama", "Jumlah Biaya", "Keterangan"};
        Object[][] isi = new Object[listBiayaLain.size()][3];
        int x = 0;
        int no = 0;
        for (BiayaLain biayaLain : listBiayaLain) {
            isi[x][0] = biayaLain.getNamaBiaya();
            isi[x][1] = "Rp " + numberFormat.format(biayaLain.getJumlahBiaya()) + ",00";
            isi[x][2] = biayaLain.getCatatan();
            x++;
        }
        tableBiayaLain2.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column1 = tableBiayaLain2.getColumnModel().getColumn(1);
        column1.setPreferredWidth(100);
        column1.setMaxWidth(100);
        column1.setCellRenderer(new RightRenderer());
    }

    private void updateTablePenjualan() {
        String[] judul = {"Nota", "Barang", "HargaJual", "Jumlah", "Sub Total"};
        Object[][] isi = new Object[listItemNota.size()][5];
        int x = 0;
        String kode = "";
        for (ItemNota itemNota : listItemNota) {
            if (!itemNota.getNota().getKode().equals(kode)) {
                kode = itemNota.getNota().getKode();
                isi[x][0] = itemNota.getNota().getKode();
            } else {
                isi[x][0] = "";
            }
            isi[x][1] = itemNota.getBarang().getNama();
            isi[x][2] = "Rp " + numberFormat.format(itemNota.getHargaJual()) + ",00";
            isi[x][3] = itemNota.getJumlah();
            isi[x][4] = "Rp " + numberFormat.format(itemNota.getHargaJual() * itemNota.getJumlah()) + ",00";
            x++;
        }
        tablePenjualan.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tablePenjualan.getColumnModel().getColumn(0);
        column0.setPreferredWidth(100);
        column0.setMaxWidth(100);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column2 = tablePenjualan.getColumnModel().getColumn(2);
        column2.setPreferredWidth(120);
        column2.setMaxWidth(120);
        column2.setCellRenderer(new RightRenderer());
        TableColumn column3 = tablePenjualan.getColumnModel().getColumn(3);
        column3.setPreferredWidth(75);
        column3.setMaxWidth(75);
        column3.setCellRenderer(new CenterRenderer());
        TableColumn column4 = tablePenjualan.getColumnModel().getColumn(4);
        column4.setPreferredWidth(120);
        column4.setMaxWidth(120);
        column4.setCellRenderer(new RightRenderer());
    }

    private void updateTablePenjualanLain() {
        String[] judul = {"Nota", "Barang", "Note", "HargaJual"};
        Object[][] isi = new Object[listItemNotaLain.size()][4];
        int x = 0;
        String kode = "";
        for (ItemNotaLain itemNotaLain : listItemNotaLain) {
            if (!itemNotaLain.getNotaLain().getKode().equals(kode)) {
                kode = itemNotaLain.getNotaLain().getKode();
                isi[x][0] = itemNotaLain.getNotaLain().getKode();
            } else {
                isi[x][0] = "";
            }
            isi[x][1] = itemNotaLain.getBarang().getNama();
            isi[x][2] = itemNotaLain.getNote();
            isi[x][3] = "Rp " + numberFormat.format(itemNotaLain.getHargaJual()) + ",00";
            x++;
        }
        tablePenjualanLain2.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tablePenjualanLain2.getColumnModel().getColumn(0);
        column0.setPreferredWidth(100);
        column0.setMaxWidth(100);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tablePenjualanLain2.getColumnModel().getColumn(3);
        column3.setPreferredWidth(120);
        column3.setMaxWidth(120);
        column3.setCellRenderer(new RightRenderer());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePenjualan = new javax.swing.JTable();
        textTotalPenjualan = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablePenjualanLain2 = new javax.swing.JTable();
        textTotalPenjualanLain2 = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablePembelian = new javax.swing.JTable();
        textTotalPembelian = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tableBiayaLain2 = new javax.swing.JTable();
        textTotalBiayaLain2 = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        dateAwal = new org.jdesktop.swingx.JXDatePicker();
        dateAkhir = new org.jdesktop.swingx.JXDatePicker();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        textHasil = new javax.swing.JTextField();
        labelBiayaLain = new javax.swing.JLabel();
        textTotalBiayaLains = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        labelPenjualanLain = new javax.swing.JLabel();
        TextTotalPenjualanLains = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        textTotalPenjualans = new javax.swing.JTextField();
        labelPenjualan = new javax.swing.JLabel();
        textTotal = new javax.swing.JTextField();
        labelTotal = new javax.swing.JLabel();

        setBorder(new org.jdesktop.swingx.border.DropShadowBorder());
        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Laporan Laba Rugi");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Penjualan"));

        tablePenjualan.setAutoCreateRowSorter(true);
        tablePenjualan.setFont(new java.awt.Font("Tahoma", 1, 11));
        tablePenjualan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tablePenjualan.setMaximumSize(new java.awt.Dimension(200000000, 65));
        jScrollPane1.setViewportView(tablePenjualan);

        textTotalPenjualan.setEditable(false);
        textTotalPenjualan.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotalPenjualan.setText("jTextField1");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                    .addComponent(textTotalPenjualan, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textTotalPenjualan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Penjualan Lain-lain"));

        tablePenjualanLain2.setAutoCreateRowSorter(true);
        tablePenjualanLain2.setFont(new java.awt.Font("Tahoma", 1, 11));
        tablePenjualanLain2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tablePenjualanLain2.setMaximumSize(new java.awt.Dimension(200000000, 65));
        jScrollPane2.setViewportView(tablePenjualanLain2);

        textTotalPenjualanLain2.setEditable(false);
        textTotalPenjualanLain2.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotalPenjualanLain2.setText("jTextField1");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
                    .addComponent(textTotalPenjualanLain2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textTotalPenjualanLain2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Pembelian"));

        tablePembelian.setAutoCreateRowSorter(true);
        tablePembelian.setFont(new java.awt.Font("Tahoma", 1, 11));
        tablePembelian.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tablePembelian.setMaximumSize(new java.awt.Dimension(200000000, 65));
        jScrollPane3.setViewportView(tablePembelian);

        textTotalPembelian.setEditable(false);
        textTotalPembelian.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotalPembelian.setText("jTextField1");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
                    .addComponent(textTotalPembelian, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textTotalPembelian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Biaya Lain-lain"));

        tableBiayaLain2.setAutoCreateRowSorter(true);
        tableBiayaLain2.setFont(new java.awt.Font("Tahoma", 1, 11));
        tableBiayaLain2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableBiayaLain2.setMaximumSize(new java.awt.Dimension(200000000, 65));
        jScrollPane4.setViewportView(tableBiayaLain2);

        textTotalBiayaLain2.setEditable(false);
        textTotalBiayaLain2.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotalBiayaLain2.setText("jTextField1");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(textTotalBiayaLain2, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textTotalBiayaLain2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Tanggal"));

        dateAwal.setFont(new java.awt.Font("Tahoma", 1, 11));

        dateAkhir.setFont(new java.awt.Font("Tahoma", 1, 11));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("Dari");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setText("Ke");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateAwal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 327, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dateAkhir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(dateAwal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(dateAkhir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Tombol"));

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jButton1.setText("Proses");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Total"));

        textHasil.setEditable(false);
        textHasil.setFont(new java.awt.Font("Tahoma", 1, 11));
        textHasil.setText("jTextField2");
        textHasil.setMaximumSize(new java.awt.Dimension(2000000000, 2147483647));

        labelBiayaLain.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelBiayaLain.setText("Biaya Lain - Lain");

        textTotalBiayaLains.setEditable(false);
        textTotalBiayaLains.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotalBiayaLains.setText("jTextField2");
        textTotalBiayaLains.setMaximumSize(new java.awt.Dimension(2000000000, 2147483647));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setText("( - )");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("=");

        labelPenjualanLain.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelPenjualanLain.setText("Penjualan Lain - Lain");

        TextTotalPenjualanLains.setEditable(false);
        TextTotalPenjualanLains.setFont(new java.awt.Font("Tahoma", 1, 11));
        TextTotalPenjualanLains.setText("jTextField2");
        TextTotalPenjualanLains.setMaximumSize(new java.awt.Dimension(2000000000, 2147483647));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("+");

        textTotalPenjualans.setEditable(false);
        textTotalPenjualans.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotalPenjualans.setText("jTextField2");
        textTotalPenjualans.setMaximumSize(new java.awt.Dimension(2000000000, 2147483647));

        labelPenjualan.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelPenjualan.setText("Penjualan");

        textTotal.setEditable(false);
        textTotal.setFont(new java.awt.Font("Tahoma", 1, 11));
        textTotal.setText("jTextField2");
        textTotal.setMaximumSize(new java.awt.Dimension(2000000000, 2147483647));

        labelTotal.setFont(new java.awt.Font("Tahoma", 1, 11));
        labelTotal.setText("Total");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelTotal)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(labelPenjualan)
                        .addGap(10, 10, 10)
                        .addComponent(textTotalPenjualans, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelPenjualanLain)
                        .addGap(10, 10, 10)
                        .addComponent(TextTotalPenjualanLains, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(labelBiayaLain))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(textTotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                    .addComponent(textHasil, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(textTotalBiayaLains, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4)
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(textTotalBiayaLains, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(labelBiayaLain)))
                            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(textHasil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5)
                                .addComponent(TextTotalPenjualanLains, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7)
                                .addComponent(textTotalPenjualans, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(labelPenjualan)
                                .addComponent(labelPenjualanLain)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTotal))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(4, 4, 4)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(6, 6, 6))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-550)/2, 800, 550);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            Map maps = labaRugiDAO.hitungTotalLabaRugi(dateAwal.getDate(), dateAkhir.getDate());
            listItemNota = (List<ItemNota>) maps.get("listItemNota");
            listItemNotaLain = (List<ItemNotaLain>) maps.get("listItemNotaLain");
            listItemPembelian = (List<ItemPembelian>) maps.get("listItemPembelian");
            listBiayaLain = (List<BiayaLain>) maps.get("listBiayaLain");
            textTotalPenjualan.setText("Rp " + numberFormat.format(maps.get("totalItemNota")) + ",00");
            textTotalPenjualans.setText("Rp " + numberFormat.format(maps.get("totalItemNota")) + ",00");
            textTotalPenjualanLain2.setText("Rp " + numberFormat.format(maps.get("totalItemNotaLain")) + ",00");
            TextTotalPenjualanLains.setText("Rp " + numberFormat.format(maps.get("totalItemNotaLain")) + ",00");
            textTotalPembelian.setText("Rp " + numberFormat.format(maps.get("totalItemPembelian")) + ",00");
            textTotalBiayaLain2.setText("Rp " + numberFormat.format(maps.get("totalBiayaLain")) + ",00");
            textTotalBiayaLains.setText("Rp " + numberFormat.format(maps.get("totalBiayaLain")) + ",00");
            updateTablePenjualan();
            updateTableBiayaLain();
            updateTablePenjualanLain();
            updateTablePembelian();
            double totalHasil = Double.parseDouble("" + maps.get("totalItemNota")) + Double.parseDouble("" + maps.get("totalItemNotaLain"));
            textHasil.setText("Rp " + numberFormat.format(totalHasil) + ",00");
            double total = totalHasil - Double.parseDouble("" + maps.get("totalBiayaLain"));
            textTotal.setText("Rp " + numberFormat.format(total) + ",00");
        } catch (Exception ex) {
            Logger.getLogger(LaporanLabaRugi.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField TextTotalPenjualanLains;
    private org.jdesktop.swingx.JXDatePicker dateAkhir;
    private org.jdesktop.swingx.JXDatePicker dateAwal;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelBiayaLain;
    private javax.swing.JLabel labelPenjualan;
    private javax.swing.JLabel labelPenjualanLain;
    private javax.swing.JLabel labelTotal;
    private javax.swing.JTable tableBiayaLain2;
    private javax.swing.JTable tablePembelian;
    private javax.swing.JTable tablePenjualan;
    private javax.swing.JTable tablePenjualanLain2;
    private javax.swing.JTextField textHasil;
    private javax.swing.JTextField textTotal;
    private javax.swing.JTextField textTotalBiayaLain2;
    private javax.swing.JTextField textTotalBiayaLains;
    private javax.swing.JTextField textTotalPembelian;
    private javax.swing.JTextField textTotalPenjualan;
    private javax.swing.JTextField textTotalPenjualanLain2;
    private javax.swing.JTextField textTotalPenjualans;
    // End of variables declaration//GEN-END:variables

    private void updateData() {
        textTotalPenjualan.setText("");
        textTotalPenjualans.setText("");
        textTotalPenjualanLain2.setText("");
        TextTotalPenjualanLains.setText("");
        textTotalPembelian.setText("");
        textTotalBiayaLain2.setText("");
        textTotalBiayaLains.setText("");
        updateTablePenjualan();
        updateTablePenjualanLain();
        updateTablePembelian();
        updateTableBiayaLain();
    }

    private void updateTablePembelian() {
        String[] judul = {"Nota", "Nama", "Jumlah", "Harga", "Sub Total"};
        Object[][] isi = new Object[listItemPembelian.size()][5];
        int x = 0;
        int no = 0;
        String kode = "";
        for (ItemPembelian itemPembelian : listItemPembelian) {
            if (!itemPembelian.getPembelian().getKode().equals(kode)) {
                kode = itemPembelian.getPembelian().getKode();
                isi[x][0] = itemPembelian.getPembelian().getKode();
            } else {
                isi[x][0] = "";
            }
            isi[x][1] = itemPembelian.getBarang().getNama();
            isi[x][2] = itemPembelian.getJumlah();
            isi[x][3] = "Rp " + numberFormat.format(itemPembelian.getHarga()) + ",00";
            isi[x][4] = "Rp " + numberFormat.format(itemPembelian.getHarga() * itemPembelian.getJumlah()) + ",00";
            x++;
        }
        tablePembelian.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });
        TableColumn column0 = tablePembelian.getColumnModel().getColumn(0);
        column0.setPreferredWidth(100);
        column0.setMaxWidth(100);
        column0.setCellRenderer(new CenterRenderer());
        TableColumn column2 = tablePembelian.getColumnModel().getColumn(2);
        column2.setPreferredWidth(75);
        column2.setMaxWidth(75);
        column2.setCellRenderer(new CenterRenderer());
        TableColumn column3 = tablePembelian.getColumnModel().getColumn(3);
        column3.setPreferredWidth(120);
        column3.setMaxWidth(120);
        column3.setCellRenderer(new RightRenderer());
        TableColumn column4 = tablePembelian.getColumnModel().getColumn(4);
        column4.setPreferredWidth(120);
        column4.setMaxWidth(120);
        column4.setCellRenderer(new RightRenderer());
    }
}
